home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
misc_pto
/
899
/
cpro1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-22
|
4KB
|
135 lines
/* TurboC v1.5 & v2.0 Source File */
/* File : CPRO-1.C
Date : March 25, 1990 -- create date
-- Finish Date
Author: Jovo J. Filipovich
Purpose : Routines used by Turbo Prolog V2.0,
these are to speed up common routines
which are much more efficient than the
declaritive brothers in TP.
*/
#include <prolog.h>
#include <prolist.h>
#include <string.h>
void maxgslistlen_0(StrList *InList, unsigned int *MaxLength);
void memgslist_0(char *gs, StrList *gsList);
void invattr_0(unsigned int InAttr, unsigned int *InvAttr);
void gslistlen_0(StrList *gsList, unsigned int *ElemCount);
void upchar_0(char Inchar, char *Upchar);
void expgslist_0(char *TargetDelete,StrList *InList,StrList **NewList);
void maxgslistlen_0(StrList *InList, unsigned int *MaxLength)
/*
Deterministic -- Returns the longest string length for the
given lis of strings.
*/
{
unsigned int Temp,Max = 0;
StrList *Current;
Current = InList; /* Init Pointers */
while ((Current->NodeType) != is_null)
{
Temp = _strlen((Current->Str));
Max = (Temp > Max) ? Temp : Max;
Current = Current->Next;
}
*MaxLength = Max;
};
void memgslist_0(char *gs, StrList *gsList)
/*
NonDeterministic -- Verifies the membership of a string in
a list of strings. If that string is found in
the list, this predicate succeeds, if not
then this predicate FAILS.
*/
{
int Found = -1;
StrList *Current;
Current = gsList;
while (((Current->NodeType) != is_null) && (Found == -1))
{
Found = (_strcmp((Current->Str),gs) == 0) ? 0 : -1;
Current = Current->Next;
};
if (Found == -1)
{
fail_cc();
};
};
void invattr_0(unsigned int InAttr, unsigned int *InvAttr)
{
*InvAttr = (InAttr & 0x08)|((InAttr & 0x07) << 4)|((InAttr & 0x70) >> 4);
};
void gslistlen_0(StrList *gsList, unsigned int *ElemCount)
{
StrList *Current;
unsigned int tcount = 0;
Current = gsList;
while ((Current->NodeType) != is_null)
{
tcount++;
Current = Current->Next;
};
*ElemCount = tcount;
};
void upchar_0(char Inchar, char *Upchar)
{
*Upchar = ((Inchar >= 'a') && (Inchar <= 'z')) ? Inchar - 0x20 : Inchar;
};
void expgslist_0(char *TargetDelete,StrList *InList,StrList **NewList)
{
StrList *Current,*Prev,*Fore;
StrList *Nlst,*Anchor;
int Found = -1;
Prev = 0x00; /* Initialy */
Current = InList;
Fore = Current->Next;
Anchor = Nlst = alloc_gstack(sizeof(StrList)); /* Allocate first node */
while ((Current->NodeType != is_null) && (Found == -1))
{
Found = (_strcmp((Current->Str),TargetDelete) == 0) ? 0 : -1;
if (Prev != 0x00)
{
Nlst->NodeType = Prev->NodeType;
Nlst->Str = alloc_gstack(_strlen(Prev->Str)+1);
_strcpy(Nlst->Str,Prev->Str);
Nlst->Next = alloc_gstack(sizeof(StrList)); /* Make another new node */
Nlst = Nlst->Next;
};
Prev = Current;
Current = Fore;
Fore = Fore->Next;
};
/* Coming into here, the item has been found and PREV holds it's location,
thus, the item in prev will be 'skipped' rendering a deletion */
while (Current->NodeType != is_null)
{
Nlst->NodeType = Current->NodeType;
Nlst->Str = alloc_gstack(_strlen(Current->Str)+1);
_strcpy(Nlst->Str,Current->Str);
Nlst->Next = alloc_gstack(sizeof(StrList)); /* Make another new node */
Nlst = Nlst->Next;
Current = Current->Next;
};
Nlst->NodeType = is_null; /* The last node has been made */
Nlst->Str = 0x00;
Nlst->Next = 0x00;
*NewList = Anchor;
};